<!-- Faraday Penetration Test IDE -->
<!-- Copyright (C) 2013  Infobyte LLC (http://www.infobytesec.com/) -->
<!-- See the file 'doc/LICENSE' for the license information -->

<section id="main" class="seccion clearfix">
  <div class="faraday-header-border-fix"></div>
  <div class="right-main">
      <div ng-controller="headerCtrl" ng-include="'scripts/commons/partials/header.html'"></div>
      <div id="reports-main" class="fila clearfix">
      <span ng-hide="!showServices" class="reports col-md-8 col-sm-8 col-xs-8 pr">
          <h3>Services for host {{hostName}}</h3>
          <div class="button-control col-md-12 col-sm-12 col-xs-12">
            <div class="control-wrapper control-new">
              <button type="button" class="btn btn-success btn-new"  title="{{workspaceData.readonly == true ? 'Read-only. Workspace disabled': 'New service'}}"  ng-click="new()" style="padding:0px 0px" ng-disabled="workspaceData.readonly === true">
                  New service
              </button>
            </div>
            <div class="control-wrapper control-edit">
              <button type="button" class="btn"  title="{{workspaceData.readonly == true ? 'Read-only. Workspace disabled': 'Edit selected services'}}" ng-click="edit()" ng-disabled="services.length == 0">
                <img src="images/icon-toolbar-edit.svg" class="edit-icon" />
              </button>
            </div>
            <div class="control-wrapper">
              <button type="button" class="btn"  title="{{workspaceData.readonly == true ? 'Read-only. Workspace disabled': 'Delete selected services'}}"  ng-click="delete()" ng-disabled="services.length == 0 || workspaceData.readonly === true">
                <img src="images/icon-toolbar-delete.svg" class="delete-icon" />
              </button>
            </div>
            <div class="space-wrapper"></div>
			    <div class="control-wrapper search-wrapper">
                    <form role="form" ng-submit="searchFor(true, searchParams)" class="ng-pristine ng-valid">
                        <div class="form-group">
                            <div class="input-group">
                                <!-- ngIf: search && search != 'confirmed=true' -->
                                <input type="text" class="form-control ng-pristine ng-valid ng-touched" placeholder="Enter keywords" ng-change="currentPage = 1" ng-model="searchParams">
                                <span class="input-group-addon glyphicon-btn" ng-click="searchFor(true, searchParams)">
                                    <img src="images/icon-toolbar-searchbar-loupe.svg" class="search-icon">
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
          </div>
          <div ng-if="loadedServices && services.length == 0">
              <h4>No services found for {{host.ip}}</h4>
          </div>
          <div ng-show="loadedServices && services.length > 0">
              <table class="table-v3 services-list table table-responsive" style="margin-top: 15px">
                  <thead>
                      <tr class="ui-grid-header">
                          <th class="ui-grid-cell-contents ui-grid-header-cell hosts-list-checkall" >
                            <input type="checkbox" ng-model="selectall" ng-click="checkAllServices()" class="ng-pristine ng-untouched ng-valid" />
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('name')">Name</span>
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('version')">Version</span>
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('ports')">Port</span>
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('protocol')">Protocol</span>
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('status')">Status</span>
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('vulns')">Vulns</span>
                          </th>
                          <th class="ui-grid-cell-contents ui-grid-header-cell">
                              <span ng-click="toggleSort('credentials')">Credentials</span>
                          </th>
                      </tr>
                  </thead>
                  <tbody>
                      <tr ng-repeat="service in filtered = (services | filter:expression) | orderBy:sortField:reverse | startFrom:(currentPage-1)*pageSize | limitTo:pageSize"
                          selection-model selection-model-type="checkbox"
                                          selection-model-mode="multiple-additive"
                                          selection-model-selected-class="multi-selected">
                          <td class="ui-grid-cell-contents checkbox-select">
                            <input type="checkbox" name="{{s._id}}"/>
                          </td>
                          <td class="ui-grid-cell-contents">
                              <a ng-href="#/host/ws/{{workspace}}/hid/{{host._id}}/search/name={{service.name}}">
                                  <span ng-bind="service.name"></span>
                              </a>
                              <osint-link query="service.name" osint="osint"></osint-link>
                          </td>
                          <td ng-bind="service.version || '-'" class="ui-grid-cell-contents"></td>
                          <td class="ui-grid-cell-contents">
                              <span ng-bind="service.ports"></span>
                              <osint-link query="'port:' + service.ports" osint="osint"></osint-link>
                          </td>
                          <td class="ui-grid-cell-contents">
                              <a ng-href="#/host/ws/{{workspace}}/hid/{{host._id}}/search/protocol={{service.protocol}}">
                                  <span ng-bind="service.protocol"></span>
                              </a>
                          </td>
                          <td ng-bind="service.status || '-'" class="ui-grid-cell-contents"></td>
                          <td class="ui-grid-cell-contents">
                              <a ng-href="#/status/ws/{{workspace}}/search/service_id={{service.id}}">
                                  <span ng-bind="service.vulns"></span>
                              </a>
                          </td>
                          <td class="ui-grid-cell-contents">
                              <a ng-href="#/credentials/ws/{{workspace}}/sid/{{service.id}}">{{service.credentials}}</a>
                          </td>
                      </tr>
                  </tbody>
              </table><!-- #hosts -->
              <div class="showPagination">
                  <div class="form-group">
                      <ul class="pagination">
                          <li><a ng-hide="prevPageDisabled()" ng-click="prevPage()"><span aria-hidden="true">&laquo;</span><span class="sr-only">Previous</span></a></li>
                          <li><a>{{currentPage}}/{{pageCount()}}</a></li>
                          <li><a ng-hide="nextPageDisabled()" ng-click="nextPage()"><span aria-hidden="true">&raquo;</span><span class="sr-only">Next</span></a></li>
                      </ul>
                      <form name="goToPage" id="goToPageStatus">
                          <div class="col-md-2">
                              <input type="number" min="0" max="{{pageCount()}}" class="form-control" ng-model="newCurrentPage" placeholder="Go to page"/>
                          </div>
                          <button class="btn btn-default" ng-click="go()">GO</button>
                          <input type="number" min="1" class="form-control vuln_per_page" ng-model=newPageSize placeholder="Number page" />
                      </form>
                  </div>
              </div><!-- .showPagination -->
          </div><!-- .reports -->
      </span>
      <div class="col-md-4 col-sm-4 col-xs-4" style="border-left: 1px solid #CCC">
          <form name="form">
              <h3>
                  Host details
                  <span style="float:right">
                      <a class="btn btn-sm btn-default" href="#/host/ws/{{workspace}}/hid/{{host.id}}/edit" ng-if="!editing">
                          <span class="glyphicon glyphicon-pencil"></span>
                          Edit
                      </a>
                      <button type="button" class="btn btn-sm btn-default"  title="{{workspaceData.readonly == true ? 'Read-only. Workspace disabled': 'Delete host'}}"  ng-click="deleteHost()" ng-if="!editing" ng-disabled="workspaceData.readonly === true">
                          <span class="glyphicon glyphicon-trash"></span>
                          Delete
                      </button>
                      <a class="btn btn-danger" href="#/host/ws/{{workspace}}/hid/{{host.id}}" ng-click="loadHosts()" ng-if="editing && !creating">Cancel</a>
                      <button class="btn btn-success" ng-disabled="form.$invalid || workspaceData.readonly == true" ng-click="ok()" ng-if="editing">OK</button>
                  </span>
              </h3>
              <div class="form-horizontal">
                  <div class="form-group" ng-class="{'has-error': !host.ip }">
                      <div class="col-md-12">
                          <strong ng-if="!editing">IP</strong>
                          <h5 ng-if="editing">IP v4 or v6</h5>
                          <label class="sr-only" for="name">IP</label>
                          <input type="text" class="form-control" id="ip" placeholder="IP" ng-model="host.ip" ng-if="editing" required/>
                          <br ng-if="!editing">
                          <span ng-if="!editing">{{host.ip}}</span>
                          <span class="help-block normal-size" ng-if="editing">
                              Example: 192.168.0.1
                          </span>
                      </div>
                  </div>
                  <div class="form-group">
                      <div class="col-md-6" style="margin-bottom: 15px">
                          <span>Owned:</span>
                          <input class="form-check-input" type="checkbox" id="owned" ng-model="host.owned" ng-disabled="!editing"></input>
                      </div>
                      <div class="col-md-12">
                          <strong ng-if="!editing">Operating System</strong>
                          <h5 ng-if="editing">Operating System</h5>
                          <label class="sr-only" for="os">Operating System</label>
                          <input type="text" class="form-control" id="os" placeholder="Operating System" ng-model="host.os" ng-if="editing"/>
                          <p ng-if="!editing">
                          <img ng-if="host.icon && host.icon != 'unknown'" ng-src="images/{{host.icon}}.png" uib-tooltip="{{host.os}}"/>
                          {{host.os}}
                          </p>
                      </div>
                      <div class="col-md-12">
                          <strong ng-if="!editing">Hostnames</strong>
                          <h5 ng-if="editing">Hostnames</h5>
                          <span class="input-group-addon button-radius" ng-click="newHostnames($event)" ng-if="editing">Add Hostname</span>
                      </div>
                      <span ng-if="editing">
                          <div class="col-md-12 input-margin" ng-repeat="hostname in host.hostnames">
                              <div class="input-group margin-bottom-sm col-md-12">
                                  <label class="sr-only" for="hostsnames">Hostname</label>
                                  <input type="text" class="form-control" id="hostsnames" placeholder="Hostname" ng-model="hostname.key" />
                                  <span class="input-group-addon" ng-click="host.hostnames.splice($index, 1)" ng-hide="host.hostnames.length == 1" ng-if="editing"><i class="fa fa-minus-circle"></i></span>
                              </div>
                          </div>
                      </span>
                      <span ng-if="!editing">
                          <div class="col-md-12 input-margin">
                              <ul>
                                  <li ng-repeat="hostname in host.hostnames">{{hostname.key}}</li>
                              </ul>
                          </div>
                      </span>
                      <div class="col-md-12">
                          <strong ng-if="!editing">MAC</strong>
                          <h5 ng-if="editing">MAC</h5>
                          <input type="text" class="form-control" id="ipv4" placeholder="MAC" ng-model="host.mac" ng-if="editing"/>
                          <p ng-if="!editing">{{host.mac}} ({{host.mac_vendor}})</p>
                      </div>
                      <div class="col-md-12">
                          <strong ng-if="!editing">Description</strong>
                          <h5 ng-if="editing">Description</h5>
                          <label class="sr-only" for="description">Description</label>
                          <textarea class="form-control" id="description" placeholder="Description" ng-model="host.description" ng-if="editing"></textarea>
                          <p ng-if="!editing">{{host.description}}</p>
                      </div>
                      <div class="col-md-12">
                          <i ng-if="!editing">
                              </br>
                              <span class="fa fa-clock-o"></span>
                              <span> Created</span>
                              <span am-time-ago="host.metadata.create_time" am-preprocess="utc"></span>
                          </i>
                      </div>
                  </div><!-- .form-group -->
              </div>
              <div style="float: right">
                  <a class="btn btn-danger" href="#/host/ws/{{workspace}}/hid/{{host.id}}" ng-click="loadHosts()" ng-if="editing && !creating">Cancel</a>
                  <a class="btn btn-danger" href="#/hosts/ws/{{workspace}}" ng-if="editing && creating">Cancel</a>
                  <button class="btn btn-success" ng-disabled="form.$invalid || workspaceData.readonly == true" ng-click="ok()" ng-if="editing">OK</button>
              </div>
          </form>
      </div>
  </div><!-- #reports-main --></div><!-- .right-main -->
</section><!-- #main -->
